/**
 * Created by Administrator on 2017/3/4.
 */
addLoadEvent(prepareAbbreviation)
function prepareAbbreviation() {
    if (!document.getElementsByTagName) return false;
    if (!document.createElement) return false;
    if (!document.createTextNode) return false;

    var abbrs = document.getElementsByTagName("abbr");
    if (abbrs.length < 1) return false;

    var descs = new Array();
    for (var i = 0 ; i < abbrs.length; i++) {
        var title = abbrs[i].getAttribute("title");
        var abbr = abbrs[i].lastChild.nodeValue;
        descs[abbr] = title;
    }

    var dlist = document.createElement("dl");
    for (var key in descs) {
        var dt = document.createElement("dt");
        dt.appendChild(document.createTextNode(key))
        dlist.appendChild(dt);

        var dd = document.createElement("dd");
        dd.appendChild(document.createTextNode(descs[key]));
        dlist.appendChild(dd);
    }

    var h2 = document.createElement("h2");
    h2.appendChild(document.createTextNode("Abbreviation"));

    document.body.appendChild(h2);
    document.body.appendChild(dlist);
}

addLoadEvent(displayCitation);
function displayCitation() {
    var quotes = document.getElementsByTagName("blockquote");
    for (var i = 0; i < quotes.length; i++) {
        var url = quotes[i].getAttribute("cite");
        if (!url) {
            return false;
        }

        var link = document.createElement("a");
        link.appendChild(document.createTextNode("source"));
        link.setAttribute("href", url);
        var superscript = document.createElement("sur");
        superscript.appendChild(link);

        quotes[i].lastElementChild.appendChild(superscript);
    }
}

addLoadEvent(displayAccesskey)
function displayAccesskey() {
    if (!document.getElementsByTagName) return false;
    if (!document.createElement) return false;
    if (!document.createTextNode) return false;
    var links = document.getElementsByTagName("a");

    if (links.length < 1) return false;
    var access = new Array();
    for (var link = 0; link <links.length; link++) {
        var key = links[link].getAttribute("accesskey");
        if (!key) continue;

        access[key] = links[link].getAttribute("href");
    }

    if (access.length < 1) return false;
    var ul = document.createElement("ul");
    for (var accessKey in access) {
        var li = document.createElement("li");
        li.appendChild(document.createTextNode(accessKey + " : " + access[accessKey]));
        ul.appendChild(li);
    }
    var header = document.createElement("h3");
    header.appendChild(document.createTextNode("Accesskey list"));

    document.body.appendChild(header);
    document.body.appendChild(ul);
}

addLoadEvent(stripeTable);
function stripeTable() {
    if (!document.getElementsByTagName) return false;

    var trs = document.getElementsByTagName("tr");
    if (trs.length < 1) return false;
    for (var i = 0; i < trs.length; i++) {
        trs[i].onmouseover = function () {
            this.style.fontWeight = 'bold';
        };
        trs[i].onmouseout = function () {
            this.style.fontWeight = 'normal';
        };
    }
}

addLoadEvent(leapTableColor)
function leapTableColor() {
    if (!document.getElementsByTagName) return false;
    var trs = document.getElementsByTagName("tr");
    var odd = false;
    for (var i = 0; i < trs.length; i++) {
        if (odd) {
            trs[i].className = 'bold';
            odd = false;
        } else {
            odd = true;
        }
    }
}
